package com.peanut.huibutie.common;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;

@ToString
public class OpenApiResult<T> implements Serializable {


    /**
     * 返回处理消息
     */
    @Getter
    @Setter
    private String message = "操作成功！";

    /**
     * 返回代码
     */
    @Getter
    @Setter
    private int code = 0;

    /**
     * 返回数据对象 data
     */
    @Getter
    @Setter
    private T data;

    @Getter
    private String sign;

    public boolean isSuccess() {
        return codeIs(OpenApiErrorCodeEnum.SUCCESS);
    }

    public boolean isSignError() {
        return codeIs(OpenApiErrorCodeEnum.Unauthorized);
    }

    public boolean isBizError() {
        return codeIs(OpenApiErrorCodeEnum.BIZ_ERROR);
    }

    public boolean isAuthError() {
        return codeIs(OpenApiErrorCodeEnum.TOKEN);
    }

    public boolean isSysError() {
        return codeIs(OpenApiErrorCodeEnum.INTERNAL_SERVER_ERROR);
    }

    private boolean codeIs(OpenApiErrorCodeEnum openApiErrorCodeEnum) {
        return code == openApiErrorCodeEnum.getCode();
    }


}